//
// Created by Administrator on 2025/3/14.
//
#include <cmath>
#include <ctime>
#include "m_thread.h"
#include <iostream>
#include <thread>
#include <unistd.h>
#include <vector>

using namespace std;

int random_num() {
    srand(time(nullptr));
    return rand();
}

void thread_fun(int num) {
    thread_local int thread_id = num;
    while(num-- > 0) {
        cout<<"thread thread_id :" <<thread_id << "; res : "<< num <<endl;
    }
}

thread gen_thread(int num) {
    thread t(thread_fun,num);
    return t;
}

void test_thread_fun() {
    int num = 10;
    int thread_id_list[num];
    vector<thread> threads_list;
    int thread_id_num ;
    for(int i=0;i < num;i++) {
        thread_id_num = random_num();
        thread_id_list[i] = thread_id_num;
        threads_list.push_back(thread(thread_fun,thread_id_num));
        sleep(1);
    };
    for (int i = 0; i < threads_list.size(); i++) {
        threads_list[i].join();
    }
    cout<<"thread fun over" <<endl;
    for (int i = 0; i < num; i++) {
        cout<<thread_id_list[i]<<endl;
    }
}

int main() {
    test_thread_fun();
}